;-------------------------------------------------------------LICENSE--------------------------------------------------------------;
;                                                                                                                                  ;
;The MAP code is written in Fortran language for magnetohydrodynamics (MHD) calculation with the adaptive mesh refinement (AMR)    ;
;and Message Passing Interface (MPI) parallelization.                                                                              ;
;                                                                                                                                  ;
;Copyright (C) 2012                                                                                                                ;
;Ronglin Jiang                                                                                                                     ;
;rljiang@ssc.net.cn                                                                                                                ;
;585 Guoshoujing Road. Pudong, Shanghai, P.R.C. 201203                                                                             ;
;                                                                                                                                  ;
;This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License         ;
;as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.             ;
;                                                                                                                                  ;
;This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of    ;
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.                        ;
;                                                                                                                                  ;
;You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software     ;
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                                                   ;
;                                                                                                                                  ;
;-------------------------------------------------------------LICENSE--------------------------------------------------------------;

pro plot_map_3d_event,event

   on_error,2

   widget_control,event.id,get_uvalue=uval
   widget_control,event.top,get_uvalue=state

   n_base = 7
   base_array = lonarr(n_base)
   base_array[0] = widget_info(event.top,find_by_uname='base2')
   base_array[1] = widget_info(event.top,find_by_uname='base3')
   base_array[2] = widget_info(event.top,find_by_uname='base4')
   base_array[3] = widget_info(event.top,find_by_uname='base5')
   base_array[4] = widget_info(event.top,find_by_uname='base6')
   base_array[5] = widget_info(event.top,find_by_uname='base7')
   base_array[6] = widget_info(event.top,find_by_uname='base8')

   if strmid(uval, 0, 3) eq 'iso' then begin
      iso_id = fix((strsplit(uval,' ',/extract))[1])
      uval = (strsplit(uval,' ',/extract))[0]
   endif
   if strmid(uval, 0, 5) eq 'slice' then begin
     slice_id = fix((strsplit(uval,' ',/extract))[1])
     uval = (strsplit(uval,' ',/extract))[0]
   endif

   if size(uval, /tname) ne 'STRING' then uval=''
   case uval of

;----------------------------------------------------------------------------------------------------------------------------------|
;  Property bases
;----------------------------------------------------------------------------------------------------------------------------------|
      'function_select':begin
         for i_base = 0, n_base - 1 do begin
            widget_control, base_array[i_base], map = 0
         endfor
         widget_control, base_array[event.value], map = 1
      end
  
;----------------------------------------------------------------------------------------------------------------------------------|
;  LoadCT
;----------------------------------------------------------------------------------------------------------------------------------|
      'ctlist':begin
         if event.index eq 0 then usr_color
         if event.index ne 0 then loadct, event.index - 1
         tvlct, rgb, /get
         state.rgbtable = rgb
         widget_control, event.top,set_uvalue = state, /no_copy
         plot_map_3d_execution, event, 'nct'
      end

;----------------------------------------------------------------------------------------------------------------------------------|
;  Time
;----------------------------------------------------------------------------------------------------------------------------------|
      't_id' : begin
         widget_control,event.id,get_value=time
         widget_control,event.top,sensitive=0
         state.time=float(time)
         plot3drddt,state.nt,t,x,y,z,1,ro,1,pr,te,1,vx,vy,vz,1,bx,by,bz,par_track,state.outputpath,state.datapath,state.time,1

         (*state.ptr_var)[*,*,*,0]=temporary(ro)
         (*state.ptr_var)[*,*,*,1]=temporary(pr)
         (*state.ptr_var)[*,*,*,2]=temporary(te)
         (*state.ptr_var)[*,*,*,3]=sqrt(vx^2+vy^2+vz^2)
         (*state.ptr_var)[*,*,*,4]=((shift(bx,0,0,-1)-shift(bx,0,0,1))/repli3d(shift(state.data_z,-1)-shift(temporary(z),1),dir='z',nx=state.nx,ny=state.ny,nz=state.nz)+  $
                                  (shift(by,-1,0,0)-shift(by,1,0,0))/repli3d(shift(state.data_x,-1)-shift(temporary(x),1),dir='x',nx=state.nx,ny=state.ny,nz=state.nz)+  $
                                  (shift(bz,0,-1,0)-shift(bz,0,1,0))/repli3d(shift(state.data_y,-1)-shift(temporary(y),1),dir='y',nx=state.nx,ny=state.ny,nz=state.nz))/4/!pi

         (*state.ptr_b)[*,*,*,0]=bx
         (*state.ptr_b)[*,*,*,1]=by
         (*state.ptr_b)[*,*,*,2]=bz
         (*state.ptr_bt)=reform(sqrt(temporary(bx)^2 + temporary(by)^2 + temporary(bz)^2),state.nx,state.ny,state.nz)

         (*state.ptr_v)[*,*,*,0]=vx
         (*state.ptr_v)[*,*,*,1]=vy
         (*state.ptr_v)[*,*,*,2]=vz
         (*state.ptr_vt)=reform(sqrt(temporary(vx)^2 + temporary(vy)^2 + temporary(vz)^2),state.nx,state.ny,state.nz)

         state.reset_main=1
         state.reset_other=1

         widget_control,event.top,sensitive=1
         widget_control,event.top,set_uvalue=state,/no_copy
      end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Cutting method
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'cuttingdirection':begin
;    widget_control,event.id,get_value=cuttingdirection
;    if cuttingdirection eq 0 then state.cuttingd='x'
;    if cuttingdirection eq 1 then state.cuttingd='y'
;    if cuttingdirection eq 2 then state.cuttingd='z'
;     widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  'cutting':begin
;    widget_control,event.id,get_value=cutting
;    if state.cuttingd eq 'x' then gridpoint=state.nx
;    if state.cuttingd eq 'y' then gridpoint=state.ny
;    if state.cuttingd eq 'z' then gridpoint=state.nz
;    state.cutting=-gridpoint*1.0*cutting/100
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Rotation
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'rotate':begin
;    if event.value eq 0 then begin
;      state.anglex=-1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'rotatex'
;    endif
;      
;    if event.value eq 1 then begin
;      state.anglex=+1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'rotatex'
;    endif
;      
;    if event.value eq 2 then begin
;      state.angley=-1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'rotatey'
;    endif
;      
;    if event.value eq 3 then begin
;      state.angley=+1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'rotatey'
;    endif
;      
;    if event.value eq 4 then begin
;      state.anglez=-1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'rotatez'
;    endif
;      
;    if event.value eq 5 then begin
;      state.anglez=+1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'rotatez'
;    endif
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  View point Moving 
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'move':begin
;    if event.value eq 0 then state.movex=state.movex-0.01
;    if event.value eq 1 then state.movex=state.movex+0.01
;    if event.value eq 2 then state.movey=state.movey-0.01
;    if event.value eq 3 then state.movey=state.movey+0.01

;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'move'
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Zoom in and out
;;----------------------------------------------------------------------------------------------------------------------------------|  
;  'scaling':begin
;    if event.value eq 0 then state.scaling=1.0/1.01
;    if event.value eq 1 then state.scaling=1.01
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'scaling'
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Draw the 3d visualization in the window
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'draw':begin
;    drawid=widget_info(event.top,find_by_uname='drawm')
;    ball_touch=state.ball_touch
;    state.ball_touch=0
;    ball_touch=0
;    widget_control,event.top,set_uvalue=state,/no_copy
;    widget_control,drawid,draw_motion_events=0
;    plot_map_3d_execution,event,'draw'
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Resuming the default plotting condition
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'default':begin
;    state.movex=-1.0-0.03
;    state.movey=-1.0+0.00
;    state.anglex=-72   ; view angle at x direction
;    state.angley=-15   ; view angle at y direction
;    state.anglez=-3    ; view angle at z direction
;    state.scaling=1.2
;    state.xrl=min(state.x)
;    state.xrh=max(state.x)
;    state.yrl=min(state.y)
;    state.yrh=max(state.y)
;    state.zrl=min(state.z)
;    state.zrh=max(state.z)
;    xrlid=widget_info(event.top,find_by_uname='xrl')
;    xrhid=widget_info(event.top,find_by_uname='xrh')
;    yrlid=widget_info(event.top,find_by_uname='yrl')
;    yrhid=widget_info(event.top,find_by_uname='yrh')
;    zrlid=widget_info(event.top,find_by_uname='zrl')
;    zrhid=widget_info(event.top,find_by_uname='zrh')
;    minvid=widget_info(event.top,find_by_uname='minv')
;    maxvid=widget_info(event.top,find_by_uname='maxv')
;    widget_control,xrlid,set_value=strcompress(state.xrl,/remove_all)
;    widget_control,xrhid,set_value=strcompress(state.xrh,/remove_all)
;    widget_control,yrlid,set_value=strcompress(state.yrl,/remove_all)
;    widget_control,yrhid,set_value=strcompress(state.yrh,/remove_all)
;    widget_control,zrlid,set_value=strcompress(state.zrl,/remove_all)
;    widget_control,zrhid,set_value=strcompress(state.zrh,/remove_all)
;    state.minv=state.minpr
;    state.maxv=state.maxpr
;    widget_control,minvid,set_value=strcompress(state.minv,/remove_all)
;    widget_control,maxvid,set_value=strcompress(state.maxv,/remove_all)
;    light0=widget_info(event.top,find_by_uname='light0')
;    light1=widget_info(event.top,find_by_uname='light1')
;    widget_control,light0,set_value=strcompress(0.2,/remove_all)
;    widget_control,light1,set_value=strcompress(0.5,/remove_all)
;    state.omodel->reset
;    state.omodel->rotate,[1,0,0],state.anglex
;    state.omodel->rotate,[0,1,0],state.angley
;    state.omodel->rotate,[0,0,1],state.anglez
;    state.omodel->scale,state.scaling,state.scaling,state.scaling  
;    state.cbname='Gas pressure'
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'draw'
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Save and resume plotting condition
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'savecon':begin
;    
;      close,/all
;      
;      d1=widget_info(event.top,find_by_uname='d1')
;      d2=widget_info(event.top,find_by_uname='d2')
;      d3=widget_info(event.top,find_by_uname='d3')
;      d4=widget_info(event.top,find_by_uname='d4')
;      d5=widget_info(event.top,find_by_uname='d5')
;      d6=widget_info(event.top,find_by_uname='d6')
;      d7=widget_info(event.top,find_by_uname='d7')
;    
;      o1=widget_info(event.top,find_by_uname='o1')
;      o2=widget_info(event.top,find_by_uname='o2')
;      o3=widget_info(event.top,find_by_uname='o3')
;      o4=widget_info(event.top,find_by_uname='o4')
;      o5=widget_info(event.top,find_by_uname='o5')
;      o6=widget_info(event.top,find_by_uname='o6')
;      o7=widget_info(event.top,find_by_uname='o7')
;      o8=widget_info(event.top,find_by_uname='o8')
;      
;      widget_control,d1,get_value=d1n
;      widget_control,d2,get_value=d2n
;      widget_control,d3,get_value=d3n
;      widget_control,d4,get_value=d4n
;      widget_control,d5,get_value=d5n
;      widget_control,d6,get_value=d6n
;      widget_control,d7,get_value=d7n
;      
;      widget_control,o1,get_value=o1v
;      widget_control,o2,get_value=o2v
;      widget_control,o3,get_value=o3v
;      widget_control,o4,get_value=o4v
;      widget_control,o5,get_value=o5v
;      widget_control,o6,get_value=o6v
;      widget_control,o7,get_value=o7v
;      widget_control,o8,get_value=o8v
;      
;    if event.value eq 0 then begin
;    
;      state.omodel->getproperty,transform=transf_matrix

;      filename=dialog_pickfile()
;      if filename eq '' then begin 
;      error=dialog_message('Data input error.',/error,title='ERROR')
;      endif else begin
;      if strmid(filename,3,4,/REVERSE_OFFSET) ne '.txt' then filename=filename+'.txt'
;      openw,1,filename
;      printf,1,state.movex,state.movey
;      printf,1,transf_matrix
;      printf,1,state.maxv,state.minv
;      printf,1,state.xrl,state.xrh,state.yrl,state.yrh,state.zrl,state.zrh
;      printf,1,d1n,d2n,d3n,d4n,d5n,d6n,d7n
;      printf,1,o1v,o2v,o3v,o4v,o5v,o6v,o7v,o8v
;      close,1
;      print,'Condition file has been saved.'
;      endelse
;      
;    endif
;    if event.value eq 1 then begin
;    
;      filename=dialog_pickfile(filter='*.txt',/fix_filter,/read)
;      if filename eq '' then begin 
;      error=dialog_message('Data input error.',/error,title='ERROR')
;      endif else begin
;      anglex=0 & angley=0 & anglez=0 & transf_matrix=fltarr(4,4)
;      openr,1,filename
;      readf,1,movex,movey
;      readf,1,transf_matrix
;      readf,1,maxv,minv
;      readf,1,xrl,xrh,yrl,yrh,zrl,zrh
;      readf,1,d1n,d2n,d3n,d4n,d5n,d6n,d7n
;      readf,1,o1v,o2v,o3v,o4v,o5v,o6v,o7v,o8v
;      close,1

;      state.omodel->setproperty,transform=transf_matrix
;      state.movex=movex
;      state.movey=movey
;      state.maxv=maxv
;      state.minv=minv
;      state.xrl=xrl
;      state.xrh=xrh
;      state.yrl=yrl
;      state.yrh=yrh
;      state.zrl=zrl
;      state.zrh=zrh

;      widget_control,d1,set_value=d1n
;      widget_control,d2,set_value=d2n
;      widget_control,d3,set_value=d3n
;      widget_control,d4,set_value=d4n
;      widget_control,d5,set_value=d5n
;      widget_control,d6,set_value=d6n
;      widget_control,d7,set_value=d7n
;      
;      widget_control,o1,set_value=o1v
;      widget_control,o2,set_value=o2v
;      widget_control,o3,set_value=o3v
;      widget_control,o4,set_value=o4v
;      widget_control,o5,set_value=o5v
;      widget_control,o6,set_value=o6v
;      widget_control,o7,set_value=o7v
;      widget_control,o8,set_value=o8v
;      
;      ol1=widget_info(event.top,find_by_uname='ol1')
;      ol2=widget_info(event.top,find_by_uname='ol2')
;      ol3=widget_info(event.top,find_by_uname='ol3')
;      ol4=widget_info(event.top,find_by_uname='ol4')
;      ol5=widget_info(event.top,find_by_uname='ol5')
;      ol6=widget_info(event.top,find_by_uname='ol6')
;      ol7=widget_info(event.top,find_by_uname='ol7')
;      ol8=widget_info(event.top,find_by_uname='ol8')
;      maxvid=widget_info(event.top,find_by_uname='maxv')
;      minvid=widget_info(event.top,find_by_uname='minv')
;      xrlid=widget_info(event.top,find_by_uname='xrl')
;      xrhid=widget_info(event.top,find_by_uname='xrh')
;      yrlid=widget_info(event.top,find_by_uname='yrl')
;      yrhid=widget_info(event.top,find_by_uname='yrh')
;      zrlid=widget_info(event.top,find_by_uname='zrl')
;      zrhid=widget_info(event.top,find_by_uname='zrh')

;      widget_control,ol1,set_value='  0-'+strmid('  '+strcompress(fix(d1n)-1,/remove_all),2,3,/reverse_offset)   
;      widget_control,ol2,set_value=strmid('  '+d1n,2,3,/reverse_offset)+'-'+strmid('  '+strcompress(fix(d2n)-1,/remove_all),2,3,/reverse_offset)
;      widget_control,ol3,set_value=strmid('  '+d2n,2,3,/reverse_offset)+'-'+strmid('  '+strcompress(fix(d3n)-1,/remove_all),2,3,/reverse_offset)
;      widget_control,ol4,set_value=strmid('  '+d3n,2,3,/reverse_offset)+'-'+strmid('  '+strcompress(fix(d4n)-1,/remove_all),2,3,/reverse_offset)
;      widget_control,ol5,set_value=strmid('  '+d4n,2,3,/reverse_offset)+'-'+strmid('  '+strcompress(fix(d5n)-1,/remove_all),2,3,/reverse_offset)
;      widget_control,ol6,set_value=strmid('  '+d5n,2,3,/reverse_offset)+'-'+strmid('  '+strcompress(fix(d6n)-1,/remove_all),2,3,/reverse_offset)
;      widget_control,ol7,set_value=strmid('  '+d6n,2,3,/reverse_offset)+'-'+strmid('  '+strcompress(fix(d7n)-1,/remove_all),2,3,/reverse_offset)
;      widget_control,ol8,set_value=strmid('  '+d7n,2,3,/reverse_offset)+'-255'
;    
;      widget_control,d1,set_value=strcompress(d1n,/remove_all)
;      widget_control,d2,set_value=strcompress(d2n,/remove_all)
;      widget_control,d3,set_value=strcompress(d3n,/remove_all)
;      widget_control,d4,set_value=strcompress(d4n,/remove_all)
;      widget_control,d5,set_value=strcompress(d5n,/remove_all)
;      widget_control,d6,set_value=strcompress(d6n,/remove_all)
;      widget_control,d7,set_value=strcompress(d7n,/remove_all)
; 
;      widget_control,maxvid,set_value=strcompress(maxv,/remove_all)
;      widget_control,minvid,set_value=strcompress(minv,/remove_all)
;      widget_control,xrlid,set_value=strcompress(xrl,/remove_all)
;      widget_control,xrhid,set_value=strcompress(xrh,/remove_all)
;      widget_control,yrlid,set_value=strcompress(yrl,/remove_all)
;      widget_control,yrhid,set_value=strcompress(yrh,/remove_all)
;      widget_control,zrlid,set_value=strcompress(zrl,/remove_all)
;      widget_control,zrhid,set_value=strcompress(zrh,/remove_all)

;      state.opac(0:fix(d1n)-1)=o1v
;      state.opac(fix(d1n):fix(d2n)-1)=o2v
;      state.opac(fix(d2n):fix(d3n)-1)=o3v
;      state.opac(fix(d3n):fix(d4n)-1)=o4v
;      state.opac(fix(d4n):fix(d5n)-1)=o5v
;      state.opac(fix(d5n):fix(d6n)-1)=o6v
;      state.opac(fix(d6n):fix(d7n)-1)=o7v
;      state.opac(fix(d7n):255)=o8v
;     
;      widget_control,event.top,set_uvalue=state,/no_copy
;      
;      plot_map_3d_execution,event,'restore'
;      endelse
;      
;    endif
;    
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Save operation
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'saveimagem':begin
;    state.anglex=0
;    state.angley=0
;    state.anglez=0
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'save'
;  end
;  
;  'saveimagetemporal':begin
;    state.anglex=0
;    state.angley=0
;    state.anglez=0
;    for timei=0,state.nt-1 do begin
;      state.time=timei
;      plot3drddt,state.nt,t,x,y,z,1,ro,1,pr,te,1,vx,vy,vz,1,bx,by,bz,par_track,state.outputpath,state.datapath,state.time,1
;  
;      (*state.ptr_var)[*,*,*,0]=temporary(ro)
;      (*state.ptr_var)[*,*,*,1]=temporary(pr)
;      (*state.ptr_var)[*,*,*,2]=temporary(te)
;      (*state.ptr_var)[*,*,*,3]=sqrt(vx^2+vy^2+vz^2)
;      (*state.ptr_var)[*,*,*,4]=((shift(bx,0,0,-1)-shift(bx,0,0,1))/repli3d(shift(state.data_z,-1)-shift(temporary(z),1),dir='z',nx=state.nx,ny=state.ny,nz=state.nz)+  $
;                                 (shift(by,-1,0,0)-shift(by,1,0,0))/repli3d(shift(state.data_x,-1)-shift(temporary(x),1),dir='x',nx=state.nx,ny=state.ny,nz=state.nz)+  $
;                                 (shift(bz,0,-1,0)-shift(bz,0,1,0))/repli3d(shift(state.data_y,-1)-shift(temporary(y),1),dir='y',nx=state.nx,ny=state.ny,nz=state.nz))/4/!pi
;  
;      (*state.ptr_b)[*,*,*,0]=bx
;      (*state.ptr_b)[*,*,*,1]=by
;      (*state.ptr_b)[*,*,*,2]=bz
;      (*state.ptr_bt)=reform(sqrt(temporary(bx)^2 + temporary(by)^2 + temporary(bz)^2),state.nx,state.ny,state.nz)
;      
;      (*state.ptr_v)[*,*,*,0]=vx
;      (*state.ptr_v)[*,*,*,1]=vy
;      (*state.ptr_v)[*,*,*,2]=vz
;      (*state.ptr_vt)=reform(sqrt(temporary(vx)^2 + temporary(vy)^2 + temporary(vz)^2),state.nx,state.ny,state.nz)
;  
;      state.reset_main=1
;      state.reset_other=1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'save'
;      widget_control,event.top,get_uvalue=state
;    endfor
;  end
;  
;  'saveimagespatial':begin
;    for rotatesavei=1,60 do begin
;    state.anglex=0
;    state.angley=6
;    state.anglez=0
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'save'
;    widget_control,event.top,get_uvalue=state
;    endfor
;  end

;  'saveimagecutting':begin
;    state.anglex=0
;    state.angley=0
;    state.anglez=0
;    for cuttingi=0,50 do begin
;    state.cutting=-state.nx*1.0*cuttingi/50
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'save'
;    widget_control,event.top,get_uvalue=state
;    endfor
;  end
;  
;----------------------------------------------------------------------------------------------------------------------------------|
;  Exit
;----------------------------------------------------------------------------------------------------------------------------------|
  'exit':begin
    plot_map_3d_execution, event, 'destroy'
  end
    
;----------------------------------------------------------------------------------------------------------------------------------|
;  Volume rendering on or off
;----------------------------------------------------------------------------------------------------------------------------------|
   'volume_switch' : begin
      if event.value eq 0 then                                                                                                     $
         state.volume_switch = 1 else                                                                                              $
         state.volume_switch = 0

      if state.volume_switch eq 1 then begin
         obj_destroy, *state.ovolume_ptr
         *state.ovolume_ptr = make_array(state.n_blocks_all[state.t_id], /obj)
         for i_volume = 0, state.n_blocks_all[state.t_id] - 1 do                                                                   $
            (*state.ovolume_ptr)[i_volume] = obj_new('idlgrvolume', hints = 2, ambient = [255, 255, 255], lighting_model = 0,      $
            interpolate = 1, zero_opacity_skip = 0, zbuffer = 1)
         state.omodel -> add, *state.ovolume_ptr
         *state.data_scalar_ptr = fltarr(state.nx, state.ny, state.nz, state.n_blocks_all[state.t_id])
         *state.x_ptr = dblarr(state.nx, state.n_blocks_all[state.t_id])
         *state.y_ptr = dblarr(state.ny, state.n_blocks_all[state.t_id])
         *state.z_ptr = dblarr(state.nz, state.n_blocks_all[state.t_id])
         rddt_map_3d, *state.x_ptr, *state.y_ptr, *state.z_ptr, *state.data_scalar_ptr,                                            $
            state.datavis_path, state.info_name, state.var_id, state.t_id
         *state.data_scalar_byt_ptr = bytscl(*state.data_scalar_ptr,                                                               $
            max = state.var_scalar_max[state.var_id], min = state.var_scalar_min[state.var_id])
      endif

      widget_control, event.top, set_uvalue = state, /no_copy
      plot_map_3d_execution, event, 'draw'
   end

   'volume_var_name' : begin
      state.datavis_id = event.index
      print, state.nx, state.ny, state.nz, state.datavis_id
      widget_control, event.top, set_uvalue = state, /no_copy
      plot_map_3d_execution, event, 'draw'
   end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Border on or off
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'show_box':begin
;    if event.value eq 0 then state.show_box=1
;    if event.value eq 1 then state.show_box=0
;    if event.value eq 2 then state.show_box=2
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Plotting variable
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'cwbuttonv':begin
;    minvid=widget_info(event.top,find_by_uname='minv')
;    maxvid=widget_info(event.top,find_by_uname='maxv')
;    if event.value eq 0 then begin
;      state.cbname='Gas pressure'
;      widget_control,minvid,set_value=strcompress(state.minpr)
;      widget_control,maxvid,set_value=strcompress(state.maxpr)
;      state.minv=state.minpr
;      state.maxv=state.maxpr
;    endif
;    if event.value eq 1 then begin
;      state.cbname='Density'
;      widget_control,minvid,set_value=strcompress(state.minro)
;      widget_control,maxvid,set_value=strcompress(state.maxro)
;      state.minv=state.minro
;      state.maxv=state.maxro
;    endif
;    if event.value eq 2 then begin
;      state.cbname='Temperature'
;      widget_control,minvid,set_value=strcompress(state.minte)
;      widget_control,maxvid,set_value=strcompress(state.maxte)
;      state.minv=state.minte
;      state.maxv=state.maxte
;    endif
;    if event.value eq 3 and state.logon eq 0 then begin
;      state.cbname='Absolute velocity'
;      widget_control,minvid,set_value=strcompress(state.minvel)
;      widget_control,maxvid,set_value=strcompress(state.maxvel)
;      state.minv=state.minvel
;      state.maxv=state.maxvel
;    endif
;    if event.value eq 4 and state.logon eq 0 then begin
;      state.cbname='Current density'
;      widget_control,minvid,set_value=strcompress(state.mincur)
;      widget_control,maxvid,set_value=strcompress(state.maxcur)
;      state.minv=state.mincur
;      state.maxv=state.maxcur
;    endif
;    state.reset_main=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Logarithm
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'logon':begin
;    if event.value eq 0 then state.logon=1
;    if event.value eq 1 then state.logon=0
;    state.reset_main=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Variable range and Plotting range (Maximum and Minimum value)
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'minv':begin
;    widget_control,event.id,get_value=minv
;    state.minv=float(minv)
;    state.reset_main=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'maxv':begin
;    widget_control,event.id,get_value=maxv
;    state.maxv=float(maxv)
;    state.reset_main=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'xrl':begin
;    widget_control, event.id, get_value = xrl
;    state.xrl = float(xrl)
;    if state.xrl gt state.xrh or state.xrl lt min(state.data_x)-1d-3 or state.xrl gt max(state.data_x)+1d-3 then begin
;      message, ' Warning: incorrect x range.', /continue
;      print,123
;    endif else begin
;    state.xrlp=round((float(state.xrl)-min(state.data_x))/(max(state.data_x)-min(state.data_x))*(state.nx-1))
;    state.x = congrid(state.data_x[state.xrlp:state.xrhp], state.nx, /minus_one, /interp)
;    state.reset_main=1
;    state.reset_other=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;    endelse
;  end
;  
;  'xrh':begin
;    widget_control, event.id, get_value = xrh
;    state.xrh = float(xrh)
;    if state.xrl gt state.xrh or state.xrh lt min(state.data_x)-1d-3 or state.xrh gt max(state.data_x)+1d-3 then begin
;      message, ' Warning: incorrect x range.', /continue
;    endif else begin
;    state.xrhp=round((float(state.xrh)-min(state.data_x))/(max(state.data_x)-min(state.data_x))*(state.nx-1))
;    state.x = congrid(state.data_x[state.xrlp:state.xrhp], state.nx, /minus_one, /interp)
;    state.reset_main=1
;    state.reset_other=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;    endelse
;  end
;    
;  'yrl':begin
;    widget_control, event.id, get_value = yrl
;    state.yrl = float(yrl)
;    if state.yrl gt state.yrh or state.yrl lt min(state.data_y)-1d-3 or state.yrl gt max(state.data_y)+1d-3 then begin
;      message, ' Warning: incorrect y range.', /continue
;    endif else begin
;    state.yrlp=round((float(state.yrl)-min(state.data_y))/(max(state.data_y)-min(state.data_y))*(state.ny-1))
;    state.y = congrid(state.data_y[state.yrlp:state.yrhp], state.ny, /minus_one, /interp)
;    state.reset_main=1
;    state.reset_other=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;    endelse
;  end
;  
;  'yrh':begin
;    widget_control, event.id, get_value = yrh
;    state.yrh = float(yrh)
;    if state.yrl gt state.yrh or state.yrh lt min(state.data_y)-1d-3 or state.yrh gt max(state.data_y)+1d-3 then begin
;      message, ' Warning: incorrect y range.', /continue
;    endif else begin
;    state.yrhp=round((float(state.yrh)-min(state.data_y))/(max(state.data_y)-min(state.data_y))*(state.ny-1))
;    state.y = congrid(state.data_y[state.yrlp:state.yrhp], state.ny, /minus_one, /interp)
;    state.reset_main=1
;    state.reset_other=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;    endelse
;  end
;    
;  
;  'zrl':begin
;    widget_control, event.id, get_value = zrl
;    state.zrl = float(zrl)
;    if state.zrl gt state.zrh or state.zrl lt min(state.data_z)-1d-3 or state.zrl gt max(state.data_z)+1d-3 then begin
;      message, ' Warning: incorrect z range.', /continue
;    endif else begin
;    state.zrlp=round((float(state.zrl)-min(state.data_z))/(max(state.data_z)-min(state.data_z))*(state.nz-1))
;    state.z = congrid(state.data_z[state.zrlp:state.zrhp], state.nz, /minus_one, /interp)
;    state.reset_main=1
;    state.reset_other=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;    endelse
;  end
;  
;  'zrh':begin
;    widget_control, event.id, get_value = zrh
;    state.zrh = float(zrh)
;    if state.zrl gt state.zrh or state.zrh lt min(state.data_z)-1d-3 or state.zrh gt max(state.data_z)+1d-3 then begin
;      message, ' Warning: incorrect z range.', /continue
;    endif else begin
;    state.zrhp=round((float(state.zrh)-min(state.data_z))/(max(state.data_z)-min(state.data_z))*(state.nz-1))
;    state.z = congrid(state.data_z[state.zrlp:state.zrhp], state.nz, /minus_one, /interp)
;    state.reset_main=1
;    state.reset_other=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;    endelse
;  end

;  'x_scaling' : begin
;    widget_control, event.id, get_value = x_scaling
;    state.x_scaling = float(x_scaling)
;    if state.x_scaling lt 0 then begin
;      message, ' Warning: incorrect x scaling.', /continue
;    endif else begin
;      widget_control, event.top, set_uvalue = state, /no_copy
;    endelse
;  end

;  'y_scaling' : begin
;    widget_control, event.id, get_value = y_scaling
;    state.y_scaling = float(y_scaling)
;    if state.y_scaling lt 0 then begin
;      message, ' Warning: incorrect y scaling.', /continue
;    endif else begin
;      widget_control, event.top, set_uvalue = state, /no_copy
;    endelse
;  end

;  'z_scaling' : begin
;    widget_control, event.id, get_value = z_scaling
;    state.z_scaling = float(z_scaling)
;    if state.z_scaling lt 0 then begin
;      message, ' Warning: incorrect z scaling.', /continue
;    endif else begin
;      widget_control, event.top, set_uvalue = state, /no_copy
;    endelse
;  end

;  'x_tick_number' : begin
;    widget_control, event.id, get_value = x_tick_number
;    state.x_tick_number = float(x_tick_number)
;    widget_control, event.top, set_uvalue = state, /no_copy
;  end

;  'y_tick_number' : begin
;    widget_control, event.id, get_value = y_tick_number
;    state.y_tick_number = float(y_tick_number)
;    widget_control, event.top, set_uvalue = state, /no_copy
;  end

;  'z_tick_number' : begin
;    widget_control, event.id, get_value = z_tick_number
;    state.z_tick_number = float(z_tick_number)
;    widget_control, event.top, set_uvalue = state, /no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Lights
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'light0':begin
;    widget_control,event.id,get_value=light0
;    state.light0=float(light0)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'light1':begin
;    widget_control,event.id,get_value=light1
;    state.light1=float(light1)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Velocity property
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'show_v':begin
;    if event.value eq 0 then begin
;      state.show_v=1
;    endif
;    if event.value eq 1 then begin
;      state.show_v=0
;      if obj_valid(state.velmodel) then obj_destroy,state.velmodel
;    endif  
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'velplanedirection':begin
;    widget_control,event.id,get_value=velplanedirection
;    if velplanedirection eq 0 then begin
;      state.velplaned='x'
;      state.velplane=-state.nx/2
;    endif
;    if velplanedirection eq 1 then begin
;      state.velplaned='y'
;      state.velplane=-state.ny/2
;    endif
;    if velplanedirection eq 2 then begin
;      state.velplaned='z'
;      state.velplane=-state.nz/2
;    endif
;     widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'velplane':begin
;    widget_control,event.id,get_value=velplane
;    if state.velplaned eq 'x' then begin
;      gridpoint=state.nx
;      state.velplane=-gridpoint*1.0*velplane/100
;    endif
;    if state.velplaned eq 'y' then begin
;      gridpoint=state.ny
;      state.velplane=-gridpoint*1.0*velplane/100
;    endif
;    if state.velplaned eq 'z' then begin
;      gridpoint=state.nz
;      state.velplane=-gridpoint*1.0*velplane/100
;    endif
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'vn':begin
;    widget_control,event.id,get_value=vn
;    state.vn=float(vn)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'vt':begin
;    widget_control,event.id,get_value=vt
;    state.vt=float(vt)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'vstep':begin
;    widget_control,event.id,get_value=vstep
;    state.vstep=float(vstep)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'varrow':begin
;    widget_control,event.id,get_value=varrow
;    state.varrow=float(varrow)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Magnetic property
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'show_b':begin
;    if event.value eq 0 then begin
;      state.show_b=1
;    endif
;    if event.value eq 1 then begin
;      state.show_b=0
;      if obj_valid(state.magmodel) then obj_destroy,state.magmodel
;    endif
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'addm':begin
;    incremid=widget_info(event.top,find_by_uname='increm')
;    widget_control,incremid,get_value=increm
;    increm=float(increm)
;    mnsid=widget_info(event.top,find_by_uname='mns')
;    mneid=widget_info(event.top,find_by_uname='mne')
;    widget_control,mnsid,get_value=mns
;    widget_control,mneid,get_value=mne
;    mns=float(mns)
;    mne=float(mne)
;    state.mns=mns+increm
;    state.mne=mne+increm
;    if state.mne gt state.par_num-1 then begin
;    state.mns=state.par_num-1
;    state.mne=state.par_num-1
;    endif
;    widget_control,mnsid,set_value=strcompress(state.mns,/remove_all)
;    widget_control,mneid,set_value=strcompress(state.mne,/remove_all)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'minusm':begin
;    incremid=widget_info(event.top,find_by_uname='increm')
;    widget_control,incremid,get_value=increm
;    increm=float(increm)
;    mnsid=widget_info(event.top,find_by_uname='mns')
;    mneid=widget_info(event.top,find_by_uname='mne')
;    widget_control,mnsid,get_value=mns
;    widget_control,mneid,get_value=mne
;    mns=float(mns)
;    mne=float(mne)
;    state.mns=mns-increm
;    state.mne=mne-increm
;    if state.mns lt 0 then begin
;    state.mns=0
;    state.mne=0
;    endif
;    widget_control,mnsid,set_value=strcompress(state.mns,/remove_all)
;    widget_control,mneid,set_value=strcompress(state.mne,/remove_all)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'mns':begin
;    widget_control,event.id,get_value=mns
;    state.mns=float(mns)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'mne':begin
;    widget_control,event.id,get_value=mne
;    state.mne=float(mne)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'mt':begin
;    widget_control,event.id,get_value=mt
;    state.mt=float(mt)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'mstep':begin
;    widget_control,event.id,get_value=mstep
;    state.mstep=float(mstep)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Test particles trajectores
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'show_par':begin
;    if event.value eq 0 then begin
;      state.show_par=1
;    endif
;    if event.value eq 1 then begin
;      state.show_par=0
;      if obj_valid(state.parmodel) then obj_destroy,state.parmodel
;    endif
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'addt':begin
;    incretid=widget_info(event.top,find_by_uname='incret')
;    widget_control,incretid,get_value=incret
;    incret=float(incret)
;    pnsid=widget_info(event.top,find_by_uname='pns')
;    pneid=widget_info(event.top,find_by_uname='pne')
;    widget_control,pnsid,get_value=pns
;    widget_control,pneid,get_value=pne
;    pns=float(pns)
;    pne=float(pne)
;    state.pns=pns+incret
;    state.pne=pne+incret
;    if state.pne gt state.par_num-1 then begin
;    state.pns=state.par_num-1
;    state.pne=state.par_num-1
;    endif
;    widget_control,pnsid,set_value=strcompress(state.pns,/remove_all)
;    widget_control,pneid,set_value=strcompress(state.pne,/remove_all)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'minust':begin
;    incretid=widget_info(event.top,find_by_uname='incret')
;    widget_control,incretid,get_value=incret
;    incret=float(incret)
;    pnsid=widget_info(event.top,find_by_uname='pns')
;    pneid=widget_info(event.top,find_by_uname='pne')
;    widget_control,pnsid,get_value=pns
;    widget_control,pneid,get_value=pne
;    pns=float(pns)
;    pne=float(pne)
;    state.pns=pns-incret
;    state.pne=pne-incret
;    if state.pns lt 0 then begin
;    state.pns=0
;    state.pne=0
;    endif
;    widget_control,pnsid,set_value=strcompress(state.pns,/remove_all)
;    widget_control,pneid,set_value=strcompress(state.pne,/remove_all)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'pns':begin
;    widget_control,event.id,get_value=pns
;    state.pns=float(pns)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'pne':begin
;    widget_control,event.id,get_value=pne
;    state.pne=float(pne)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'plinet':begin
;    widget_control,event.id,get_value=plinet
;    state.plinet=float(plinet)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Resistivity region
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'show_res':begin
;    if event.value eq 0 then state.show_res=1
;    if event.value eq 1 then state.show_res=0
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Opacity
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'setopacity':begin
;  
;    d1=widget_info(event.top,find_by_uname='d1')
;    d2=widget_info(event.top,find_by_uname='d2')
;    d3=widget_info(event.top,find_by_uname='d3')
;    d4=widget_info(event.top,find_by_uname='d4')
;    d5=widget_info(event.top,find_by_uname='d5')
;    d6=widget_info(event.top,find_by_uname='d6')
;    d7=widget_info(event.top,find_by_uname='d7')
;    
;    widget_control,d1,get_value=d1n
;    widget_control,d2,get_value=d2n
;    widget_control,d3,get_value=d3n
;    widget_control,d4,get_value=d4n
;    widget_control,d5,get_value=d5n
;    widget_control,d6,get_value=d6n
;    widget_control,d7,get_value=d7n
;    
;    ol1=widget_info(event.top,find_by_uname='ol1')
;    ol2=widget_info(event.top,find_by_uname='ol2')
;    ol3=widget_info(event.top,find_by_uname='ol3')
;    ol4=widget_info(event.top,find_by_uname='ol4')
;    ol5=widget_info(event.top,find_by_uname='ol5')
;    ol6=widget_info(event.top,find_by_uname='ol6')
;    ol7=widget_info(event.top,find_by_uname='ol7')
;    ol8=widget_info(event.top,find_by_uname='ol8')
;    
;    widget_control,ol1,set_value='  0-'+d1n
;    widget_control,ol2,set_value=d1n+'-'+d2n
;    widget_control,ol3,set_value=d2n+'-'+d3n
;    widget_control,ol4,set_value=d3n+'-'+d4n
;    widget_control,ol5,set_value=d4n+'-'+d5n
;    widget_control,ol6,set_value=d5n+'-'+d6n
;    widget_control,ol7,set_value=d6n+'-'+d7n
;    widget_control,ol8,set_value=d7n+'-255'

;    o1=widget_info(event.top,find_by_uname='o1')
;    o2=widget_info(event.top,find_by_uname='o2')
;    o3=widget_info(event.top,find_by_uname='o3')
;    o4=widget_info(event.top,find_by_uname='o4')
;    o5=widget_info(event.top,find_by_uname='o5')
;    o6=widget_info(event.top,find_by_uname='o6')
;    o7=widget_info(event.top,find_by_uname='o7')
;    o8=widget_info(event.top,find_by_uname='o8')
;    
;    widget_control,o1,get_value=o1v
;    widget_control,o2,get_value=o2v
;    widget_control,o3,get_value=o3v
;    widget_control,o4,get_value=o4v
;    widget_control,o5,get_value=o5v
;    widget_control,o6,get_value=o6v
;    widget_control,o7,get_value=o7v
;    widget_control,o8,get_value=o8v
;    
;    state.opac(0:fix(d1n))=o1v
;    state.opac(fix(d1n+1):fix(d2n))=o2v
;    state.opac(fix(d2n+1):fix(d3n))=o3v
;    state.opac(fix(d3n+1):fix(d4n))=o4v
;    state.opac(fix(d4n+1):fix(d5n))=o5v
;    state.opac(fix(d5n+1):fix(d6n))=o6v
;    state.opac(fix(d6n+1):fix(d7n))=o7v
;    state.opac(fix(d7n+1):255)=o8v
;    
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'nvol'
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Isosurface
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'add_isosurface':begin
;    for iso_id=0,15 do begin
;      if state.isosurface_list[iso_id] eq -1 then break
;    endfor
;      if iso_id eq 16 then break
;    state.isosurface_list[iso_id]=iso_id
;    widget_control, event.top, update = 0
;    base_iso=widget_base(base5,uname='isosurface'+ strcompress(iso_id), frame = 1,  /column ,/align_top)
;    baset=widget_base(base_iso, /row)
;    basett=widget_base(baset,/nonexclusive)
;    button=widget_button(basett,uvalue='iso_show'+ strcompress(iso_id),uname='iso_show'+ strcompress(iso_id),xsize=20)
;    label=widget_label(baset,value='Isosurface'+ strcompress(iso_id),xsize=100)
;    text=widget_text(baset,value='1.0',xsize=5,uname='iso_val'+ strcompress(iso_id),  $  
;      uvalue='iso_val'+ strcompress(iso_id),all_events=1,/editable)
;    button=widget_button(baset,xsize=100,value='Delete'+ strcompress(iso_id),  $
;      uvalue='iso_del'+ strcompress(iso_id))
;    baset=widget_base(base_iso,/row)
;    label=widget_label(baset,value='Opacity',xsize=60)
;    slider=widget_slider(baset,uvalue='iso_slider'+ strcompress(iso_id),minimum=0,maximum=100,value=state.isosurface_opac[iso_id],xsize=160)
;    state.isosurface_obj[iso_id]=obj_new('idlgrpolygon',shading=1,texture_interp=1,emission=[10,10,45])
;    state.omodel->add,state.isosurface_obj[iso_id],position=0
;    widget_control, event.top, update = 1
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'iso_show':begin
;    state.isosurface_show[iso_id] = 1-state.isosurface_show[iso_id]
;    if state.isosurface_show[iso_id] eq 0 then state.isosurface_obj[iso_id]->setproperty,hide=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'iso_slider':begin
;    widget_control,event.id,get_value=opac
;    state.isosurface_opac[iso_id]=opac
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'iso_del':begin
;    baseid=widget_info(base5,find_by_uname='isosurface'+strcompress(iso_id))
;    state.isosurface_list[iso_id]=-1
;    state.isosurface_show[iso_id]=0
;    widget_control,baseid,/destroy
;    if obj_valid(state.isosurface_obj[iso_id]) then obj_destroy,state.isosurface_obj[iso_id]
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'isosurface'
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Slice
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'add_slice':begin
;    for slice_id=0,15 do begin
;      if state.slice_list[slice_id] eq -1 then break
;    endfor
;      if slice_id eq 16 then break
;    widget_control, event.top, update = 0
;    state.slice_list[slice_id]=slice_id
;    base_slice=widget_base(base6,uname='slice'+ strcompress(slice_id),/align_top,/column,frame=1)
;    baset=widget_base(base_slice,/row)
;    basett=widget_base(baset,/nonexclusive)
;    button=widget_button(basett,uvalue='slice_show'+ strcompress(slice_id),uname='slice_show'+ strcompress(slice_id),xsize=20)
;    label=widget_label(baset,value='Slice'+ strcompress(slice_id),xsize=50)
;    button=widget_button(baset,xsize=80,value='Delete'+ strcompress(slice_id),uvalue='slice_del'+ strcompress(slice_id))
;    label=widget_label(baset,value='Opacity',xsize=50)
;    slider=widget_slider(baset,uvalue='slice_slider1'+ strcompress(slice_id),minimum=0,maximum=100,value=state.slice_opac[slice_id],xsize=80)
;    baset=widget_base(base_slice,/row)
;    label=widget_label(baset,value='x>',xsize=15)
;    slider=widget_slider(baset,uvalue='slice_slider2'+ strcompress(slice_id),minimum=-90,maximum=90,value=state.slice_rotatex[slice_id],xsize=120)
;    label=widget_label(baset,value='y>',xsize=15)
;    slider=widget_slider(baset,uvalue='slice_slider3'+ strcompress(slice_id),minimum=-90,maximum=90,value=state.slice_rotatey[slice_id],xsize=120)
;    baset=widget_base(base_slice,/row)
;    label=widget_label(baset,value='x-',xsize=15)
;    slider=widget_slider(baset,uvalue='slice_slider5'+ strcompress(slice_id),minimum=1,maximum=99,value=state.slice_movex[slice_id],xsize=80)
;    label=widget_label(baset,value='y-',xsize=15)
;    slider=widget_slider(baset,uvalue='slice_slider6'+ strcompress(slice_id),minimum=1,maximum=99,value=state.slice_movey[slice_id],xsize=80)
;    label=widget_label(baset,value='z-',xsize=15)
;    slider=widget_slider(baset,uvalue='slice_slider7'+ strcompress(slice_id),minimum=1,maximum=99,value=state.slice_movez[slice_id],xsize=80)
;    widget_control, event.top, update = 1
;    state.oslice[slice_id]=obj_new('idlgrpolygon',shading=1,texture_interp=1,emission=[10,10,45])
;    state.omodel->add,state.oslice[slice_id],position=0
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_show':begin
;    state.slice_show[slice_id] = 1-state.slice_show[slice_id]
;    if state.slice_show[slice_id] eq 0 then state.oslice[slice_id]->setproperty,hide=1
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_slider1':begin
;    widget_control,event.id,get_value=opac
;    state.slice_opac[slice_id]=opac
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_slider2':begin
;    widget_control,event.id,get_value=rotatex
;    state.slice_rotatex[slice_id]=rotatex
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_slider3':begin
;    widget_control,event.id,get_value=rotatey
;    state.slice_rotatey[slice_id]=rotatey
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_slider5':begin
;    widget_control,event.id,get_value=movex
;    state.slice_movex[slice_id]=movex
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_slider6':begin
;    widget_control,event.id,get_value=movey
;    state.slice_movey[slice_id]=movey
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_slider7':begin
;    widget_control,event.id,get_value=movez
;    state.slice_movez[slice_id]=movez
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'slice_del':begin
;    baseid=widget_info(base6,find_by_uname='slice'+strcompress(slice_id))
;    state.slice_list[slice_id]=-1
;    state.slice_show[slice_id]=0
;    state.slice_opac[slice_id]=100
;    state.slice_rotatex[slice_id]=0
;    state.slice_rotatey[slice_id]=0
;    state.slice_movex[slice_id]=50
;    state.slice_movey[slice_id]=50
;    state.slice_movez[slice_id]=50
;    widget_control,baseid,/destroy
;    if obj_valid(state.oslice[slice_id]) then obj_destroy,state.oslice[slice_id]
;    widget_control,event.top,set_uvalue=state,/no_copy
;    plot_map_3d_execution,event,'slice'
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Symbol
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'syms':begin
;    widget_control,event.id,get_value=syms
;    state.syms=float(syms)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Colors
;;----------------------------------------------------------------------------------------------------------------------------------|  
;  'tc':begin
;    widget_control,event.id,get_value=tc
;    state.tc=[state.colorr[tc-1],state.colorg[tc-1],state.colorb[tc-1]]
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
;  
;  'bc':begin
;    widget_control,event.id,get_value=bc
;    state.bc=[state.colorr[bc-1],state.colorg[bc-1],state.colorb[bc-1]]
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  Number of axis and colorbar labels
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'lat':begin
;    widget_control,event.id,get_value=lat
;    state.lat=fix(lat)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'lbt':begin
;    widget_control,event.id,get_value=lbt
;    state.lbt=fix(lbt)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  colorbar on or not
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'show_colorbar':begin
;    if event.value eq 0 then state.show_colorbar=1
;    if event.value eq 1 then state.show_colorbar=0
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;;----------------------------------------------------------------------------------------------------------------------------------|
;;  text size
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'textsize1':begin
;    widget_control,event.id,get_value=textsize1
;    state.textsize1=float(textsize1)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'textsize2':begin
;    widget_control,event.id,get_value=textsize2
;    state.textsize2=float(textsize2)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'textsize3':begin
;    widget_control,event.id,get_value=textsize3
;    state.textsize3=float(textsize3)
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'axes_switch':begin
;    if event.select eq 0 then begin
;      state.otitlex->setproperty,hide=0
;      state.otitley->setproperty,hide=0
;      state.otitlez->setproperty,hide=0
;      state.omodel_axis->setproperty,hide=1
;    endif
;    if event.select eq 1 then begin
;      state.otitlex->setproperty,hide=1
;      state.otitley->setproperty,hide=1
;      state.otitlez->setproperty,hide=1
;      state.omodel_axis->setproperty,hide=0
;    endif
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'move_axis_x':begin
;    widget_control,event.id,get_value=move_axis_x
;    state.move_axis_x=float(move_axis_x)
;    state.omodel->getproperty,transform=model_matrix
;    state.omodel_axis->setproperty,transform=model_matrix
;    state.omodel_axis->translate,state.move_axis_x,state.move_axis_y,state.move_axis_z
;    state.omodel_axis->scale,0.2,0.2,0.2
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'move_axis_y':begin
;    widget_control,event.id,get_value=move_axis_y
;    state.move_axis_y=float(move_axis_y)
;    state.omodel->getproperty,transform=model_matrix
;    state.omodel_axis->setproperty,transform=model_matrix
;    state.omodel_axis->translate,state.move_axis_x,state.move_axis_y,state.move_axis_z
;    state.omodel_axis->scale,0.2,0.2,0.2
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end

;  'move_axis_z':begin
;    widget_control,event.id,get_value=move_axis_z
;    state.move_axis_z=float(move_axis_z)
;    state.omodel->getproperty,transform=model_matrix
;    state.omodel_axis->setproperty,transform=model_matrix
;    state.omodel_axis->translate,state.move_axis_x,state.move_axis_y,state.move_axis_z
;    state.omodel_axis->scale,0.2,0.2,0.2
;    widget_control,event.top,set_uvalue=state,/no_copy
;  end
    
;;----------------------------------------------------------------------------------------------------------------------------------|
;;  track ball
;;----------------------------------------------------------------------------------------------------------------------------------|
;  'drawm':begin
;;----------------------------------------------------------------------------------------------------------------------------------|
;;   Note: the event.type is the same in both left click and right click 
;;----------------------------------------------------------------------------------------------------------------------|
;    drawid=widget_info(event.top,find_by_uname='drawm')
;    ball_touch=state.ball_touch

;;----------------------------------------------------------------------------------------------------------------------|
;;   reset track ball 
;;----------------------------------------------------------------------------------------------------------------------|
;    if event.press eq 0 and event.release ne 0 then begin
;      state.ball_touch=0
;      ball_touch=0
;      widget_control,event.top,set_uvalue=state,/no_copy
;      widget_control,drawid,draw_motion_events=0
;    endif

;;----------------------------------------------------------------------------------------------------------------------|
;;   for the mouse right events
;;----------------------------------------------------------------------------------------------------------------------|
;    if ball_touch eq 1 then begin
;      state.movex=state.movex+1.0*(state.mouse_posx-event.x)/state.win_sizex
;      state.movey=state.movey+1.0*(state.mouse_posy-event.y)/state.win_sizey
;      state.mouse_posx=event.x
;      state.mouse_posy=event.y
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'draw'
;    endif

;    if event.press eq 1 and event.release eq 0 then begin
;      state.ball_touch=1
;      ball_touch=1
;      state.mouse_posx=event.x
;      state.mouse_posy=event.y
;      widget_control,drawid,draw_motion_events=1
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'draw'
;    endif

;;----------------------------------------------------------------------------------------------------------------------|
;;   for the mouse right events
;;----------------------------------------------------------------------------------------------------------------------|
;    if ball_touch eq 3 or event.press eq 4 and event.release eq 0 then begin
;      ball_result=state.oball->update(event,transform=ball_matrix,mouse=4)
;      if ball_result then begin 
;        state.omodel->getproperty,transform=model_matrix 
;        state.omodel->setproperty,transform=model_matrix # ball_matrix
;        state.omodel->getproperty,transform=model_matrix
;        state.omodel_axis->setproperty,transform=model_matrix
;        state.omodel_axis->translate,state.move_axis_x,state.move_axis_y,state.move_axis_z
;        state.omodel_axis->scale,0.2,0.2,0.2
;        plot_map_3d_execution,event,'draw'
;      endif
;    endif

;    if event.press eq 4 and event.release eq 0 then begin
;      state.ball_touch=3
;      ball_touch=3
;      widget_control,event.top,set_uvalue=state,/no_copy  
;      widget_control,drawid,draw_motion_events=1
;    endif

;;----------------------------------------------------------------------------------------------------------------------|
;;   for the mouse wheel events
;;----------------------------------------------------------------------------------------------------------------------|
;    if event.type eq 7 then begin
;      if event.clicks eq 1 then state.scaling=1.05
;      if event.clicks eq -1 then state.scaling=1.0/1.05
;      state.ball_touch=2
;      ball_touch=2
;      widget_control,event.top,set_uvalue=state,/no_copy
;      plot_map_3d_execution,event,'scaling'
;    endif

;;----------------------------------------------------------------------------------------------------------------------|
;;   for first time expose
;;----------------------------------------------------------------------------------------------------------------------|
;    if event.type eq 4 then begin
;      plot_map_3d_execution,event,'draw'
;    endif

;  end

  else:
endcase

end
